package com.gaofei.account.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gaofei.account.domain.AccountTbl;
import com.gaofei.account.service.IAccountTblService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaofei
 * @since 2021-05-29
 */
@RestController
@RequestMapping("/accountTbl")
public class AccountTblController {


    @Autowired
    IAccountTblService accountTblService;
    //扣钱操作
    @RequestMapping("reduce")
    public Boolean reduce(String uid,Integer orderMoney){
        QueryWrapper<AccountTbl> w = new QueryWrapper<>();
        w.eq("user_id", uid);
        AccountTbl one = accountTblService.getOne(w);
        //如果账户余额大于等于订单金额,扣减账户金额
        if(one.getMoney()>=orderMoney){
            one.setMoney(one.getMoney() - orderMoney);
            accountTblService.updateById(one);
            return true;
        }
        return false;
    }
}

